/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * OrderDetails.java
 *
 * Created on Dec 10, 2009, 1:39:07 PM
 */

package GUI;

import Business.Bill_BS;
import Business.CustomerProcess_BS;
import Business.BillProcess_BS;
import Business.loadBillDetails;
import DAO.Bill_DAO;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JOptionPane;

/**
 *
 * @author trangnn_b00557
 */
public class BillDetails extends javax.swing.JDialog {

//    private int bId;
    CustomerProcess_BS supplierBO = new CustomerProcess_BS();
    private loadBillDetails load;
    private Bill_BS bs;
    /** Creates new form OrderDetails */
    public BillDetails(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

//    public void setOrderId(int bId) {
//        this.bId = bId;
//    }
    public void setOrder(Bill_BS bill) {
         BillProcess_BS op = BillProcess_BS.getOrder();
       this.bs= bill;
       //System.out.println(pcId);
       try {
            load = op.viewOrderDetails(bill.getBID());
            tbProductList.setModel(load);
            //System.out.println(tblPurchaseDetails.getRowCount());
             float totalPrice=0;
            int row= tbProductList.getRowCount();
            //System.out.println(row);
            for(int i=0; i<row; i++)
            {
                Float subPrice= (Float)tbProductList.getValueAt(i,3);
                //System.out.println(tblPurchaseDetails.getValueAt(i, 0));
                totalPrice += subPrice;
            }
            bs.setTotal(totalPrice);
            lblTotal.setText(String.valueOf(totalPrice));
        } catch (Exception e) {
            e.printStackTrace();
        }
        txtDate.setText(bill.getBdate());
        txtName.setText(bill.getCName());

        SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
        String orDate = format.format((bill.getBDeliveryDate()).getTime());
        txtDeliveryDate.setText(orDate);
        txtDeleveryAddress.setText(bill.getBDeliveryAddress());
        txtDiscount.setText(String.valueOf(bill.getBDiscount()));
        txtPaid.setText(String.valueOf(bill.getBPaid()));
        txtUnpaid.setText(String.valueOf(bill.getBUnpaid()));
        if(bill.getBStatus() == 0)
        {
            txtStatus.setText("UnPaid");
        }
        else if(bill.getBStatus() == 1)
        {
            txtStatus.setText("Part Payment");
        }
        else
        {
            txtStatus.setText("Paid");
        }

    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        lblDateOrder = new javax.swing.JLabel();
        lblDeliveryDate = new javax.swing.JLabel();
        txtDeliveryDate = new javax.swing.JTextField();
        lblDeliveryAddress = new javax.swing.JLabel();
        txtDeleveryAddress = new javax.swing.JTextField();
        txtDate = new javax.swing.JLabel();
        lblName = new javax.swing.JLabel();
        txtName = new javax.swing.JLabel();
        btUpdateOrder = new javax.swing.JButton();
        btClose = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbProductList = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        txtUnpaid = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        lblPaid = new javax.swing.JLabel();
        txtPay = new javax.swing.JTextField();
        lblTotal = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtPaid = new javax.swing.JLabel();
        btPay = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtBalance = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        lblDiscount = new javax.swing.JLabel();
        txtDiscount = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        txtStatus = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Bill Details", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.TOP, new java.awt.Font("Monotype Corsiva", 1, 36), new java.awt.Color(51, 102, 0))); // NOI18N

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Customer Information"));

        lblDateOrder.setFont(new java.awt.Font("Tahoma", 1, 11));
        lblDateOrder.setText("Date : ");

        lblDeliveryDate.setFont(new java.awt.Font("Tahoma", 1, 11));
        lblDeliveryDate.setText("Delivery Date : ");

        lblDeliveryAddress.setFont(new java.awt.Font("Tahoma", 1, 11));
        lblDeliveryAddress.setText("Delivery Address : ");

        txtDeleveryAddress.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDeleveryAddressActionPerformed(evt);
            }
        });

        txtDate.setText("jLabel4");

        lblName.setFont(new java.awt.Font("Tahoma", 1, 11));
        lblName.setText("Name : ");

        txtName.setText("jLabel1");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(77, 77, 77)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblDateOrder)
                    .addComponent(lblDeliveryAddress)
                    .addComponent(lblDeliveryDate)
                    .addComponent(lblName))
                .addGap(43, 43, 43)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtDate, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtDeliveryDate, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtDeleveryAddress, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE))
                .addGap(238, 238, 238))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtDate)
                    .addComponent(lblDateOrder, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblName)
                    .addComponent(txtName))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(lblDeliveryDate)
                        .addGap(18, 18, 18)
                        .addComponent(lblDeliveryAddress))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(txtDeliveryDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtDeleveryAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(23, 23, 23))
        );

        btUpdateOrder.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Img/Edit.png"))); // NOI18N
        btUpdateOrder.setText("Update");
        btUpdateOrder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btUpdateOrderActionPerformed(evt);
            }
        });

        btClose.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Img/Button-Close-icon.png"))); // NOI18N
        btClose.setText("Close");
        btClose.setActionCommand("buttton1");
        btClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCloseActionPerformed(evt);
            }
        });

        tbProductList.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tbProductList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbProductListMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tbProductList);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Pay"));

        txtUnpaid.setText("0");

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel1.setText("Total : ");

        lblPaid.setFont(new java.awt.Font("Tahoma", 1, 11));
        lblPaid.setText("Pay : ");

        txtPay.setText("0");

        lblTotal.setText("0");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel5.setText("Paid : ");

        jLabel2.setText("$");

        txtPaid.setText("0");

        btPay.setText("Pay");
        btPay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btPayActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel3.setText("Balance : ");

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel6.setText("Unpaid: ");

        txtBalance.setText("0");

        jLabel4.setText("$");

        lblDiscount.setFont(new java.awt.Font("Tahoma", 1, 11));
        lblDiscount.setText("Discount : ");

        txtDiscount.setText("0");

        jLabel7.setText("%");

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel8.setText("Status : ");

        txtStatus.setText("jLabel9");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(44, 44, 44)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(lblPaid)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtPay, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 60, Short.MAX_VALUE)
                        .addComponent(btPay)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtBalance, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4)
                        .addGap(78, 78, 78))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel8)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(lblDiscount)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtDiscount)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 54, Short.MAX_VALUE)
                                .addComponent(jLabel7)
                                .addGap(31, 31, 31)
                                .addComponent(jLabel5)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(txtPaid, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel6)
                                .addGap(18, 18, 18)
                                .addComponent(txtUnpaid, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(txtStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtStatus))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(lblTotal)
                    .addComponent(lblDiscount)
                    .addComponent(txtDiscount)
                    .addComponent(txtUnpaid)
                    .addComponent(jLabel6)
                    .addComponent(txtPaid)
                    .addComponent(jLabel5)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblPaid)
                            .addComponent(jLabel3)
                            .addComponent(txtBalance)
                            .addComponent(jLabel4))
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtPay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2)))
                    .addComponent(btPay))
                .addGap(14, 14, 14))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 597, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(383, Short.MAX_VALUE)
                .addComponent(btUpdateOrder)
                .addGap(27, 27, 27)
                .addComponent(btClose)
                .addGap(21, 21, 21))
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btUpdateOrder)
                    .addComponent(btClose))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtDeleveryAddressActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDeleveryAddressActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtDeleveryAddressActionPerformed

    private void btPayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btPayActionPerformed
        // TODO add your handling code here:
        Float paid = Float.valueOf(txtPaid.getText()).floatValue();
        float totalPrice= bs.getTotal();
        float unpaid= Float.valueOf(txtUnpaid.getText().trim()).floatValue();
        float pay = Float.valueOf(txtPay.getText().trim()).floatValue();
        float balance = Float.valueOf(txtBalance.getText().trim()).floatValue();

        if(pay !=0) {
            if(pay > unpaid) {
                JOptionPane.showMessageDialog(this,"Extra money : " + (pay - unpaid) + " $","Report",JOptionPane.DEFAULT_OPTION);
            } else{
                unpaid = unpaid - pay;
                balance = unpaid - pay;
                paid += pay ;
                bs.setBPaid(paid);
                bs.setBUnpaid(unpaid);
                txtPaid.setText(String.valueOf(bs.getBPaid()));
                txtUnpaid.setText(String.valueOf(bs.getBUnpaid()));
                txtPaid.setText(String.valueOf(bs.getBPaid()));
                txtUnpaid.setText(String.valueOf(bs.getBUnpaid()));
            }
        } else {
            balance= unpaid;
            bs.setBPaid(paid);
            bs.setBUnpaid(unpaid);
        }

        txtBalance.setText(String.valueOf(unpaid));
}//GEN-LAST:event_btPayActionPerformed

    private void tbProductListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbProductListMouseClicked
        // TODO add your handling code here:
        if (evt.getClickCount() > 1) {
            int row = tbProductList.getSelectedRow();
        }
    }//GEN-LAST:event_tbProductListMouseClicked

    private void btCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCloseActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_btCloseActionPerformed

    private void btUpdateOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btUpdateOrderActionPerformed
        // TODO add your handling code here:
        Bill_DAO od = new Bill_DAO();
        //boolean flag = false;
        try {
            Date today = new Date();
            SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
            String bDate = format.format(today.getTime());

            Date bDeliveryDate = format.parse(txtDeliveryDate.getText());

            String bDeliveryAddress = txtDeleveryAddress.getText();
            Float paid = Float.parseFloat(txtPaid.getText());
            Float unPaid = Float.parseFloat(txtUnpaid.getText());
            //ps = new Purchase_BS(pcId,paid,unPaid,pcDate);
            bs.setBDeliveryDate(bDeliveryDate);
            bs.setBDeliveryAddress(bDeliveryAddress);
            bs.setBPaid(paid);
            bs.setBUnpaid(unPaid);
            bs.setBdate(bDate);
            if(unPaid> 0)
            {
                bs.setBStatus(1);
            }
            else if(unPaid == 0)
            {
                bs.setBStatus(2);
            }
            else
            {
                bs.setBStatus(0);
            }
            if(!od.updateOrder(bs)) {
                JOptionPane.showMessageDialog(this, "Cannot Update Purchase");
                return;
            } else {
                JOptionPane.showMessageDialog(this, "Update Successfull!");
            }
            this.dispose();
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_btUpdateOrderActionPerformed

    /**
    * @param args the command line arguments
    */
 
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btClose;
    private javax.swing.JButton btPay;
    private javax.swing.JButton btUpdateOrder;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblDateOrder;
    private javax.swing.JLabel lblDeliveryAddress;
    private javax.swing.JLabel lblDeliveryDate;
    private javax.swing.JLabel lblDiscount;
    private javax.swing.JLabel lblName;
    private javax.swing.JLabel lblPaid;
    private javax.swing.JLabel lblTotal;
    private javax.swing.JTable tbProductList;
    private javax.swing.JLabel txtBalance;
    private javax.swing.JLabel txtDate;
    private javax.swing.JTextField txtDeleveryAddress;
    private javax.swing.JTextField txtDeliveryDate;
    private javax.swing.JLabel txtDiscount;
    private javax.swing.JLabel txtName;
    private javax.swing.JLabel txtPaid;
    private javax.swing.JTextField txtPay;
    private javax.swing.JLabel txtStatus;
    private javax.swing.JLabel txtUnpaid;
    // End of variables declaration//GEN-END:variables

}
